var scanList = [];
var input = prompt('Functions: scan, replace or precise(get info)', 'Input desired function');

input = input.toLowerCase();
var scan = function (tag) {
    for (i = 0; i <= document.getElementsByTagName(tag).length; i++) {
        if (i === document.getElementsByTagName(tag).length) {
            var r = confirm('Done!\n\n' + 'Found ' + document.getElementsByTagName(tag).length + ' results for ' + tag + '.\n \nWould you like to display the results?');
            if (r === true) {
                for (j = 0; j < scanList.length; j++) {
                    var k = confirm('LISTING ' + j + ': \n\n' + scanList[j]);
                  if (k === false){
                  break;
                    }
                }
            }
        } else {
            scanList.push(document.getElementsByTagName(tag)[i].innerHTML);
        }
    }
};
var replace = function (tag, num, newVal) {
    document.getElementsByTagName(tag)[num].innerHTML = newVal;
};
var precise = function (tag, num) {
    alert(document.getElementsByTagName(tag)[num].innerHTML);
};
if (input === 'scan') {
    var option = prompt('Input a tag to scan', 'Tag');
    scan(option);
} else if (input === 'replace') {
    var option = prompt('Input a tag', 'Tag');
    var option2 = prompt('Input a tag #', 'Tag #');
    var option3 = prompt('Input a the new value', 'New Value');
    replace(option, option2, option3);
} else if (input === 'precise') {
    var option = prompt('Input a tag', 'Tag');
    var option2 = prompt('Input a tag #', 'Tag #');
    precise(option, option2);
} else {
    alert('Sorry "' + input + '" is not a valid function.');
}